package com.scpii.universal.util;

import java.io.File;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ImgAndFilePath {

	public static final String ENTERP_WORK_DIR = "WORKDIR" + File.separator
			+ "ENTERPRISE";

	public static final String ENTERP_ANDROID = File.separator + "ANDROID";
	public static final String ENTERP_IOS = File.separator + "IOS";

	public static final String ENTERP_ICON = File.separator + "ICON";
	public static final String ENTERP_NAVIGATE = File.separator + "NAVIGATE";
	public static final String ENTERP_BACKGROUND = File.separator
			+ "BACKGROUND";
	public static final String ENTERP_LOADING = File.separator + "LOADING";
	public static final String ENTERP_CATELOG = File.separator + "CATELOG";
	public static final String ENTERP_PRODUCT = File.separator + "PRODUCT";
	public static final String ENTERP_NEWS = File.separator + "NEWS";
	public static final String ENTERP_ACTIVE = File.separator + "ACTIVE";

	// 上传剪切图片后存放地址
	public static final String ENTERP_SMALL = File.separator + "SMALL";
	// 上传原图存放地址
	public static final String ENTERP_DETAIL = File.separator + "DETAIL";
	public static final String TEMP_FOLDER = File.separator + "WORKDIR"
			+ File.separator + "TEMP";
	public static final String IOS_DLIST = File.separator + "DLIST";
	public static final String PNS = File.separator + "PNS";
	public static final String VIDEO = File.separator + "VIDEO";
	public static final String AUDIO = File.separator + "AUDIO";
	public static final String EC = File.separator + "EC";
	public static final String USER = File.separator + "USER";
	public static final String SHOP = File.separator + "SHOP";
	public static final String PUSH = File.separator + "PUSH";

	private static Log log = LogFactory.getLog(ImgAndFilePath.class);

	/**
	 * 注册时创建企业图片目录
	 * 
	 * @param rootPath
	 * @param enterpId
	 * @author weny 2012-7-12下午01:28:36
	 */
	public static void createEnterWork(String rootPath, int enterpId) {
		if (enterpId > 0) {
			String workpath = rootPath + ENTERP_WORK_DIR + "_" + enterpId;
			File file = new File(workpath);
			if (!file.exists()) {
				boolean bool = file.mkdirs();
				if (bool) {
					log.info("创建目录成功!");
				} else {
					log.error("创建目录失败!");
				}
			}
		}
	}

	/**
	 * 创建应用图片目录
	 * 
	 * @param rootPath
	 * @param enterpId
	 * @param appId
	 */
	public static void createWorkPic(String rootPath, int enterpId, int appId) {
		if (enterpId > 0) {
			String baseDir = rootPath + ENTERP_WORK_DIR + "_" + enterpId
					+ File.separator + appId;
			String[] pathStr = new String[] {
					baseDir + ENTERP_ANDROID + ENTERP_ICON + ENTERP_SMALL,
					baseDir + ENTERP_ANDROID + ENTERP_ICON + ENTERP_DETAIL,
					baseDir + ENTERP_ANDROID + ENTERP_NAVIGATE + ENTERP_SMALL,
					baseDir + ENTERP_ANDROID + ENTERP_NAVIGATE + ENTERP_DETAIL,
					baseDir + ENTERP_ANDROID + ENTERP_BACKGROUND + ENTERP_SMALL,
					baseDir + ENTERP_ANDROID + ENTERP_BACKGROUND
							+ ENTERP_DETAIL,
					baseDir + ENTERP_ANDROID + ENTERP_LOADING + ENTERP_SMALL,
					baseDir + ENTERP_ANDROID + ENTERP_LOADING + ENTERP_DETAIL,
					baseDir + ENTERP_ANDROID + ENTERP_CATELOG + ENTERP_SMALL,
					baseDir + ENTERP_ANDROID + ENTERP_CATELOG + ENTERP_DETAIL,
					baseDir + ENTERP_ANDROID + ENTERP_PRODUCT + ENTERP_SMALL,
					baseDir + ENTERP_ANDROID + ENTERP_PRODUCT + ENTERP_DETAIL,
					baseDir + ENTERP_ANDROID + ENTERP_NEWS + ENTERP_SMALL,
					baseDir + ENTERP_ANDROID + ENTERP_NEWS + ENTERP_DETAIL,
					baseDir + ENTERP_ANDROID + ENTERP_ACTIVE + ENTERP_SMALL,
					baseDir + ENTERP_ANDROID + ENTERP_ACTIVE + ENTERP_DETAIL,

					baseDir + ENTERP_IOS + ENTERP_ICON + ENTERP_SMALL,
					baseDir + ENTERP_IOS + ENTERP_ICON + ENTERP_DETAIL,
					baseDir + ENTERP_IOS + ENTERP_NAVIGATE + ENTERP_SMALL,
					baseDir + ENTERP_IOS + ENTERP_NAVIGATE + ENTERP_DETAIL,
					baseDir + ENTERP_IOS + ENTERP_BACKGROUND + ENTERP_SMALL,
					baseDir + ENTERP_IOS + ENTERP_BACKGROUND + ENTERP_DETAIL,
					baseDir + ENTERP_IOS + ENTERP_LOADING + ENTERP_SMALL,
					baseDir + ENTERP_IOS + ENTERP_LOADING + ENTERP_DETAIL,
					baseDir + ENTERP_IOS + ENTERP_CATELOG + ENTERP_SMALL,
					baseDir + ENTERP_IOS + ENTERP_CATELOG + ENTERP_DETAIL,
					baseDir + ENTERP_IOS + ENTERP_PRODUCT + ENTERP_SMALL,
					baseDir + ENTERP_IOS + ENTERP_PRODUCT + ENTERP_DETAIL,
					baseDir + ENTERP_IOS + ENTERP_NEWS + ENTERP_SMALL,
					baseDir + ENTERP_IOS + ENTERP_NEWS + ENTERP_DETAIL,
					baseDir + ENTERP_IOS + ENTERP_ACTIVE + ENTERP_SMALL,
					baseDir + ENTERP_IOS + ENTERP_ACTIVE + ENTERP_DETAIL,

					// 不分IOS/安卓
					baseDir + ENTERP_ICON, // 应用ICON
					baseDir + ENTERP_LOADING, // 应用LOADING
					baseDir + ENTERP_CATELOG + ENTERP_DETAIL, // 分类缩略图
					baseDir + IOS_DLIST, // 存放IOS dlist文件
					baseDir + PNS, baseDir + VIDEO, baseDir + AUDIO,
					baseDir + EC, baseDir + USER, baseDir + SHOP

			};
			if (pathStr != null && pathStr.length > 0) {
				for (String path : pathStr) {
					if (path != null && path.trim().length() > 0) {
						File file = new File(path);
						if (!file.exists()) {
							boolean bool = file.mkdirs();
							if (bool) {
								log.info("创建目录成功!");
							} else {
								log.error("创建目录失败!");
							}
						}
					}
				}
			}
		}
	}

}
